﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.BlackApart.Business;
using blackhouse.BlackApart.Business.Apartments;
using blackhouse.BlackApart.Business.Reservations;

namespace blackhouse.Aparts.Web.DataSources {
    internal static class WebReservationExtensions {

        public static string GetGroupShortName(this IWebReservation reservation) {
            IApartmentGroup group = reservation.GetGroup();
            return group != null ? group.ShortName : "";
        }

        public static IApartmentGroup GetGroup(this IWebReservation reservation) {
            if (reservation == null || reservation.ApartmentReservation.Length == 0) return null;
            int apartmentId = reservation.ApartmentReservation.First().ApartmentId;
            IApartment apartment = Factory.Instance().GetApartment(apartmentId);
            if (apartment != null)
                return apartment.Group;
            else
                return null;
        }

    }
}